package com.example;


import com.example.demo.client.common.ViewKey;
import com.example.demo.client.view.*;
import com.example.demo.client.common.CommonRequest;
import com.example.demo.ds.MyHashMap;
import com.example.demo.server.common.SessionUtils;


public class DemoApplication {

    // 符号映射表
    private static final MyHashMap<String, View> myHashMap = new MyHashMap<String, View>() {{
        put(ViewKey.LOGIN, new LoginView());
        put(ViewKey.REGISTER, new RegisterView());
        put(ViewKey.WRITE, new WriteView());
        put(ViewKey.LIST, new ListView());
        put(ViewKey.MY_LIST, new MyListView());
        put(ViewKey.DETAIL, new DetailView());
        put(ViewKey.UPDATE, new UpdateView());
    }};

    public static void init() {
        SessionUtils.removeSession();
        SessionUtils.removeCookie();
    }

    public static void main(String[] args) {
        init();
        CommonRequest request = CommonRequest.createRequest(ViewKey.LOGIN);
        while(true) {
            request = myHashMap.get(request.getUrl()).jump(request);
        }
    }

//    设计草稿
//    public static void main(String[] args) {
//        int n = 1;
//        View[] views = {
//                null,
//                new WriteView(),
//                new DetailView(),
//                new ListView(),
//                new LoginView(),
//                new MyListView(),
//                new RegisterView(),
//                new UpdateView()
//        };
//        while(true) {
//            n = views[n].jump();
//        }
//    }
}
